##=============================================================================
## Appendix Figure 10
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "hrbrthemes")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

plot <- dat %>% 
  dplyr::select(wave, survival_mindset) %>% 
  mutate(wave = factor(wave, labels = c("July 2022 \n (n = 1,830)", 
                                        "February 2023 \n (n = 1,838)"))) %>%
  mutate(median_survive = ifelse(wave == "July 2022 \n (n = 1,830)", 0.30, 0.34))


ggplot(plot, aes(x = survival_mindset, color = wave, fill = wave)) +
  geom_histogram(alpha = 0.6) +
  facet_wrap(~wave) +
  geom_vline(aes(xintercept = median_survive), color = "grey25", lty = 2, lwd = 1) +  
  scale_fill_grey() +
  scale_color_grey() +
  labs(x = "Survival Mindset", y = "Count", fill = "Wave", color = "Wave") +
  theme_ipsum(axis_title_size = 18, 
              base_size = 18, 
              caption_size = 14,
              plot_title_size = 24) +
  theme(legend.position="none",
        panel.spacing = unit(0.1, "lines"),
        strip.text.x = element_text(size = 18))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================